<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <!--<script type="text/javascript" src="../Js/jquery.sorted.js"></script>-->
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/script.js" ></script>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
</head>
<body>
<form class="form-inline definewidth m20" action="index.html" method="get">  
    学生姓名：
    <input type="text" name="name" id="name"class="abc input-default" placeholder="" value="">&nbsp;&nbsp;
    <button type="submit" class="btn btn-primary" onclick="query(1)">查询</button>&nbsp;&nbsp;
    <button type="button" class="btn btn-success"  ><a href="add.html">新增</a></button>
</form>
<table class="table table-bordered table-hover definewidth m10" >
    <thead>
    <tr>
        <th>学生姓名</th>
        <th>性别</th>
        <th>年龄</th>
        <th>班级</th>
        <th>url</th>
        <th>管理操作</th>
    </tr>
    </thead>

    <tbody id="tb">

    </tbody>
</table>
<div class="inline pull-right page">
        <!-- 10122 条记录 1/507 页-->
    <span  id="tiao">10122条记录</span>/<span  id="ye">507页</span>
    <input type="hidden" id="pageNo">
    <a href="javascript:beforPage();">上一页</a>
    <a href="javascript:nextPage();">下一页</a>
   <!-- <span class='current'>1</span>
    <a href='#'>2</a>
    <a href='/chinapost/index.php?m=Label&a=index&p=3'>3</a>
    <a href='#'>4</a><a href='#'>5</a>  &lt;!&ndash;<a href='#' >下5页</a>&ndash;&gt;
    <a href='#' >最后一页</a> -->
</div>
</body>
</html>
<script>

    $(function () {
        query(1);//默认显示第一页
    })

    function beforPage() {
        var b =parseInt($("#pageNo").val()) - 1;
        if(b < 1) {b =1 }
        query(b);
    }
    function nextPage() {
        var b =parseInt($("#pageNo").val()) + 1;
        query(b);
    }

    function query(a) {

        var name = $("#name").val();//获取姓名文本框
        console.log(name);

        $.ajax({
            type:"post",
            url:baseUrl+"/zhangmengna!queryPage",//controller --->404
            data:{"name":name,"pageNo":a},
            dataType:"json",
            success:function (res) {
                var ht ='';
                $("#tb").empty();
                $.each(res.data,function (i,v) {
                    ht = ht+ '<tr class="id9">'+
                        '<td>'+v.name+'</td>' +
                        '<td>'+v.sex+'</td>'+
                        '<td>'+v.age+'</td>'+
                        '<td>'+v.bname+'</td>'+
                        '<td>'+v.url+'</td>'+
                        '<td><a href="add.html?'+v.id+'">修改</a> | <a class="del" data-id=".id9" href="javascript:del('+v.id+')">删除</a></td>' +
                        '</tr>';
                });

                $("#tb").append(ht);
                 $("#tiao").text('共'+res.totalCount+'条记录');
                 $("#ye").text('共'+res.totalPage+'页');
                 $("#pageNo").val(res.currentPage);
            }
        });

    }
    $(function () {

        $('#addnew').click(function(){

            window.location.href="add.html";
        });

    });
    function del(e){
        alert(e);
        $.ajax({
            type: "POST",
            url: baseUrl+"/zhangmengna!del",
            data:{"zmnEntity.id":e},  //--->index与控制类中的变量index是一样的
            dataType:"json",
            async:false,
            success: function (res) {

                if(res=='1'){
                    if(confirm("确定要删除吗？"))
                    {
                        alert("删除成功")
                        var url = "index.html";
                        window.location.href=url;

                    }
                }

            },
            error: function(data) {

                alert("系统出现异常")
            }
        });
    }


</script>